import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', name: 'login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/choose', name: 'choose', component: () => import('@/views/choose/index'), hidden: true },
  { path: '/home', name: 'home-page', component: () => import('@/views/home-page/index'), hidden: true },
  { path: '/home/detail/:id', name: 'home-detail', component: () => import('@/views/home-page/detail/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true }
]

export const asyncRouterMap = [
  {
    path: '/exercise',
    component: Layout,
    redirect: '/exercise/random',
    name: 'exercise',
    meta: { title: '做题', icon: 'example', roles: ['admin'] },
    children: [
      {
        path: 'random',
        name: 'exercise-random',
        component: () => import('@/views/exercise/random'),
        meta: { title: '随机练习', icon: 'form' }
      },
      {
        path: 'chapter/list',
        name: 'exercise-chapter-home',
        component: () => import('@/views/exercise/chapter/home'),
        meta: { title: '章节练习', icon: 'nested' }
      },
      {
        path: 'chapter/exercise/:examType/:subjectCategoryId/:subjectChapterId',
        name: 'exercise-chapter-exercise',
        component: () => import('@/views/exercise/chapter/exercise'),
        hidden: true
      },
      {
        path: 'testpaper',
        name: 'exercise-testpaper',
        component: () => import('@/views/exercise/test-paper'),
        meta: { title: '我的试卷', icon: 'table' }
      },
      {
        path: 'testanswer/:id/:name',
        name: 'exercise-testanswer',
        component: () => import('@/views/exercise/test-answer'),
        meta: { title: '试卷答题', icon: 'table' },
        hidden: true
      },
      {
        path: 'testresult/:testId?/:handPaperId?/:name?',
        name: 'exercise-testresult',
        component: () => import('@/views/exercise/test-result'),
        meta: { title: '试卷结果', icon: 'table' },
        hidden: true
      },
      {
        path: 'testresultdetails/:testId?/:handPaperId?',
        name: 'exercise-result-details',
        component: () => import('@/views/exercise/test-result-details'),
        meta: { title: '试卷详情', icon: 'table' },
        hidden: true
      },
      {
        path: 'mistake',
        name: 'exercise-mistake',
        component: () => import('@/views/exercise/mistake'),
        meta: { title: '我的错题', icon: 'table' }
      }
    ]
  },
  {
    path: '/mycourse',
    component: Layout,
    redirect: '/mycourse/course',
    name: 'mycourse',
    meta: { title: '我的课程', icon: 'tree', roles: ['admin'] },
    children: [
      {
        path: 'course',
        name: 'mycourse-course',
        component: () => import('@/views/mycourse/course'),
        meta: { title: '我的课程', icon: 'tree' }
      },
      {
        path: 'seevideo/:url?/:courseCover?',
        name: 'mycourse-seevideo',
        component: () => import('@/views/mycourse/seeVideo'),
        meta: { title: '观看视频', icon: 'table' },
        hidden: true
      },
      {
        path: 'answer/:id',
        name: 'mycourse-answer',
        component: () => import('@/views/mycourse/answer'),
        meta: { title: '答题', icon: 'table' },
        hidden: true
      },
      {
        path: 'course/result/:courseId/:handPaperId',
        name: 'course-test-result',
        component: () => import('@/views/mycourse/course-test-result'),
        meta: { title: '课程试卷结果', icon: 'table' },
        hidden: true
      },
      {
        path: 'detailsanswer/:courseId/:handPaperId',
        name: 'mycourse-detailsAnswer',
        component: () => import('@/views/mycourse/detailsAnswer'),
        meta: { title: '课程试卷答题详情', icon: 'table' },
        hidden: true
      }
    ]
  },
  { path: '*', redirect: '/home', hidden: true }
]

export default new Router({
  mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
